<template>
  <el-dialog
    :title="headTitle"
    :visible.sync="dialogVisible"
    width="400px"
    :before-close="handleClose"
    :close-on-click-modal="false"
  >
    <div class="dialog">
      <div class="dialog-list">
        <label require="true">用户名:</label>
        <div class="span">
          <el-select
          filterable 
            size="small"
            v-model="formData.userId"
            placeholder="请选择"
          >
            <el-option
              v-for="item in userAll"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId"
            >
            </el-option>
          </el-select>
        </div>
      </div>
      <!-- <div class="dialog-list">
        <label require="true">手机号:</label>
        <div class="span">
          <el-input size="small" v-model="formData.deptShortName"></el-input>
        </div>
      </div> -->
      <div class="dialog-list">
        <label require="true">所属组织:</label>
        <div class="span">
          <el-select
            size="small"
            v-model="formData.deptId"
            placeholder="请选择"
          >
            <el-option
              v-for="item in treeData"
              :key="item.deptId"
              :label="item.deptName"
              :value="item.deptId"
            >
            </el-option>
          </el-select>
        </div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="save">提交</el-button>
      <el-button @click="(dialogVisible = false), updateKey()">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
import Qs from "qs";
export default {
  props: {
    headTitle: {},
    treeData: {}
  },
  data() {
    return {
      dialogVisible: false,
      userAll:[],
      formData: {
        userId: "",
        deptId: "",
      },
      dateRange: "",
      value: "",
      value1: "",
      pData: {}
    };
  },
  methods: {
    open(data) {
      console.log(data)
      this.getuserAll();
      this.pData = data;
      this.formData.deptId=data.deptId
      this.dialogVisible = true;
    },
    updateKey() {
      this.$emit("update:keyIndex", new Date().getTime());
    },
    handleClose(done) {
      this.dialogVisible = false;
      this.updateKey();
    },
    save() {
        request({
        url: "/system/org/addOrgUser",
        method: "post",
        headers: { "content-type": "application/x-www-form-urlencoded" },
        data: Qs.stringify({ ...this.formData })
      }).then(res => {
        this.$emit("reload");
        this.handleClose()
        console.log(res);
      });
    },
    getuserAll() {
      request({
        url: "/system/user/userAll",
        method: "post"
      }).then(res => {
          this.userAll=res.data
        console.log(res);
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.el-dialog__wrapper {
  .el-dialog__body {
  }

  .dialog {
    width: 100%;
    max-height: 400px;
    overflow: auto;
    padding: 10px;

    &-list {
      width: 100%;
      height: 40px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      margin: 10px 0;

      label {
        width: 90px;
        text-align: right;
        padding: 0 10px;
      }

      label[require="true"]::before {
        content: "*";
        color: red;
      }

      .span {
        width: calc(100% - 90px);
        height: 100%;
        display: flex;
        align-items: center;

        .el-select,
        .el-date-editor {
          width: 100% !important;
        }
      }
    }
  }
}
</style>
